from file_sender import FileSender
import os

def progress_callback(callback_type, *args):
    """进度回调函数"""
    if callback_type == 'total_files':
        print(f"总文件数：{args[0]}")
    elif callback_type == 'file_progress':
        filename, current, total = args
        if total > 0:
            percentage = (current * 100) / total
            print(f"文件 {filename} 进度：{current}/{total} ({percentage:.2f}%)")
    elif callback_type == 'complete':
        print("传输完成")
    elif callback_type == 'error':
        print(f"错误：{args[0]}")

def main():
    # 创建发送器实例
    sender = FileSender()
    
    # 设置进度回调
    sender.set_progress_callback(progress_callback)
    
    # 设置要传输的文件夹路径
    folder_path = "D:\\FtmSpace\\Obsidian".strip()
    if not os.path.exists(folder_path):
        print(f"错误：文件夹 {folder_path} 不存在")
        return
    
    # 设置端口号
    port = 3000
    host = "192.168.1.9"
    
    print(f"\n开始传输文件夹：{folder_path}")
    print(f"请求地址：{host}:{port}")
    
    try:
        # 开始传输
        sender.send_folder(folder_path, port,host)
    except KeyboardInterrupt:
        print("\n传输被用户中断")
    except Exception as e:
        print(f"\n传输出错：{str(e)}")

if __name__ == "__main__":
    main()
